package coreconcurrency.paradigm;



import coreconcurrency.entity.Student;

import java.util.concurrent.CompletableFuture;

/**
 * create by yongli on 2021-06-28 21:
 *  CompletableFuture，也是可以执行任务的
 */

public class CompleteFutureTest {
    public static void main(String[] args)  throws Exception{
        CompletableFuture<String> completableFuture = new CompletableFuture<>();
        // 辅助的返回值
        completableFuture.complete("the eye");
        String abc = "EJB";
        Student su = new Student();
        CompletableFuture<String> ret1 = CompletableFuture.supplyAsync(() -> abc);
        CompletableFuture<String> ret2 = CompletableFuture.supplyAsync(() -> {
            su.setAge(1232);
            String sb = "future";
            System.out.println("this is no result");
            return "ok";
        });
        // 回调方法
        ret2.whenComplete((ele,ex)->{
            System.out.println(ele);
        });
        // get方法是一个阻塞方法
        System.out.println(ret2.get());


    }
}
